package edu.calvin.djs32.cs214.interpreters.calculator.primitives;


import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import edu.calvin.cs214.hobbes2008.ApplicationTIR;
import edu.calvin.cs214.hobbes2008.IdentifierTIR;
import edu.calvin.cs214.hobbes2008.IntegerTIR;
import edu.calvin.cs214.hobbes2008.StringTIR;
import edu.calvin.cs214.hobbes2008.TupleTIR;

public class TRefPrimitiveTest {

	@Before
	public void setUp() throws Exception {
	}
	
	@Test
	public void shouldApply(){
		assertEquals(new IntegerTIR(2), new TRefPrimitive().apply(null, new TupleTIR(new IntegerTIR(2), new IntegerTIR(3), new IntegerTIR(4)), new IntegerTIR(0)));
		assertEquals(new IntegerTIR(2), new TRefPrimitive().apply(null, new TupleTIR(new IntegerTIR(1), new IntegerTIR(2), new IntegerTIR(3)), new IntegerTIR(1)));
		assertEquals(new StringTIR("a"), new TRefPrimitive().apply(
				null, new TupleTIR(new StringTIR("a"), 
								new IntegerTIR(3), 
								new ApplicationTIR(new IdentifierTIR("+"), new TupleTIR(new IntegerTIR(2), new IntegerTIR(5)))), new IntegerTIR(0)));
		assertEquals(new IntegerTIR(3), new TRefPrimitive().apply(
				null, new TupleTIR(new StringTIR("a"), 
								new IntegerTIR(3), 
								new ApplicationTIR(new IdentifierTIR("+"), new TupleTIR(new IntegerTIR(2), new IntegerTIR(5)))), new IntegerTIR(1)));
		assertEquals(new ApplicationTIR(new IdentifierTIR("+"), new TupleTIR(new IntegerTIR(2), new IntegerTIR(5))), new TRefPrimitive().apply(
				null, new TupleTIR(new StringTIR("a"), 
								new IntegerTIR(3), 
								new ApplicationTIR(new IdentifierTIR("+"), new TupleTIR(new IntegerTIR(2), new IntegerTIR(5)))), new IntegerTIR(2)));
	}

}
